package com.cgx.controller;

import com.cgx.entity.message.Session;
import com.cgx.entity.message.SessionUser;
import com.cgx.service.SessionService;
import com.cgx.vo.ResultVo;
import com.cgx.vo.websocket.MessageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author chenguanxin
 * @date 2021-05-26 22:16
 */
@Controller
@CrossOrigin("*")
@RequestMapping("/session")
public class SessionController {

    @Autowired
    private SessionService sessionService;

    @ResponseBody
    @RequestMapping("/findAllSessionByUserId")
    public List<Session> findAllSessionByUserId(@RequestBody String userId) {
        return sessionService.findAllSessionByUserId(userId);
    }

    @ResponseBody
    @RequestMapping("/saveAllSession")
    public List<Session> saveAllSession(@RequestBody List<Session> sessionList) {
        return sessionService.saveAllSession(sessionList);
    }

    @ResponseBody
    @RequestMapping("/saveAllSessionUser")
    public List<SessionUser> saveAllSessionUser(@RequestBody List<SessionUser> sessionList) {
        return sessionService.saveAllSessionUser(sessionList);
    }

    @ResponseBody
    @RequestMapping("/sendMessageBySessionId")
    public Map<String, ResultVo> sendMessageBySessionId(@RequestBody MessageVo messageVo) {
        return sessionService.sendMessageBySessionId(messageVo);
    }

    @ResponseBody
    @RequestMapping("/getSessionBySessionId")
    public List<Session> getSessionBySessionId(@RequestBody List<String> idList) {
        return sessionService.getSessionBySessionId(idList);
    }
    @ResponseBody
    @RequestMapping("/getSessionUserBySessionId")
    public List<SessionUser> getSessionUserBySessionId(@RequestBody List<String> idList) {
        return sessionService.getSessionUserBySessionId(idList);
    }
}
